<!DOCTYPE html>
<html lang="zh">

<head>
	<meta charset="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<meta http-equiv="X-UA-Compatible" content="ie=edge" />
	<link rel="stylesheet" type="text/css" href="../img-font/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="../css/css.css" />
	<link rel="stylesheet" type="text/css" href="../css/weui.css" />
	<script src="../js/jquery.min.js"></script>
	<script src="../js/main.js"></script>
	<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
	<script src="../js/Url.js"></script>
	<title></title>
	<style type="text/css">
		.fanjian {
			height: 100%;
			display: block;
			color: #000;
			font-size: 24px;
			line-height: 30px;
			float: left;
			text-indent: 24px;
			position: absolute;
			top: 10px;
			left: 0;
		}

		.Homer {
			height: 100%;
			margin-top: 50px;
			padding-top: 10px;
			text-align: center;
		}

		.weui-btn_primary {
			background: #0094FF;
			margin-top: 10px;
		}

		.js_dialog {
			display: none;
		}

		.current {
			height: 30px;
			line-height: 30px;
			text-align: left;
			padding-left: 15px;
		}
	</style>
</head>

<body>
<div class="topnav">
	<a href="javascript:history.go(-1)"><span class="fanjian iconfont icon-xia"></span></a>绑定手机号
</div>
<div class="Homer">
	<div class="current">
		当前绑定手机号：<span class="span_val" style="color: red;"></span>
	</div>
	<div class="weui-cells">
		<div class="weui-cell weui-cell_select weui-cell_select-before">
			<div class="weui-cell__hd">
				<select class="weui-select" name="select2">
					<option value="1">+86</option>
				</select>
			</div>
			<div class="weui-cell__bd">
				<input class="weui-input phone" type="number" pattern="[0-9]*" placeholder="请输入号码">
			</div>
		</div>
	</div>
	<div class="weui-cells">
		<div class="weui-cell weui-cell_select weui-cell_select-before">
			<div class="weui-cell__hd">
				<select class="weui-select" name="select2">
					<option value="1">密码</option>
				</select>
			</div>
			<div class="weui-cell__bd">
				<input class="weui-input pword" type="password" placeholder="请输入密码">
			</div>

		</div>
	</div>

	<div class="weui-btn-area button_s">
		<a class="weui-btn weui-btn_primary" href="javascript:" id="showTooltips">确定</a>
	</div>
</div>
<div class="js_dialog" id="iosDialog2" style="opacity: 1;">
	<div class="weui-mask"></div>
	<div class="weui-dialog">
		<div class="weui-dialog__bd">您输入的手机号码格式有误，请重新输入</div>
		<div class="weui-dialog__ft">
			<a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary">确定</a>
		</div>
	</div>
</div>
</body>
<script type="text/javascript">
    $(function() {
        //已绑定手机号
        $.ajax({
            type: "get",
            url: "/foot/user/queryMobilePhoneByOpenid",
            contentType: "application/json; charset=utf-8",
            success: function(res) {
                if(res.error_code == 0) {
                    $('.span_val').html(res.data.mobilePhone);
                } else {
                    $('.span_val').html(res.data);
                }
            }
        });

        $('.button_s').on('click', function() {

            var mobilePhone = $('.phone').val();
            var password = $('.pword').val();
            var pattern = /0?(13|14|15|17|18)[0-9]{9}/;
            var veert = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/
            if(pattern.test(mobilePhone) == true && mobilePhone.length !== 0) {
                if(veert.test(password) == true && password.length !== 0) {
                    $.ajax({
                        type: "POST",
                        url: "/foot/user/updateMobilePhone",
                        data: {
                            'mobilePhone': mobilePhone,
                            'password': password
                        },
                        success: function(res) {
                            if(res.error_code == 0) {
                                $('.span_val').html(res.data.mobilePhone)
                                fun(res.data);
                            } else if(res.error_code == 1) {
                                fun(res.data);
                            } else {
                                fun(res.data);
                            }
                        }
                    });
                }else{
                    $('.js_dialog').show();
                    $('.weui-dialog__bd').html('密码必须为6-12位数字字母，且不能为空！')
                }
            } else if(pattern.test(mobilePhone) == false) {
                $('.js_dialog').show();
            }
        })

        $('.weui-dialog__btn_primary').on('click', function() {
            $('.js_dialog').hide();
        })
        var span_val = $('.current >span').html();

    })

    function fun(sty) {
        $('.js_dialog').show();
        $('.weui-dialog__bd').html(sty);
        $('.weui-dialog__btn_primary').on('click', function() {
            window.location.reload();
        })
    }
</script>

</html>